package com.itheima.Test;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class Test004服务器端 {
    public static void main(String[] args) throws IOException {
        //创建对象;
        ServerSocketChannel ssc = ServerSocketChannel.open();
        //绑定端口
        ssc.bind(new InetSocketAddress(1315));
        //链接客户端;
        SocketChannel sc = ssc.accept();
        //准备数组;
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        //读取
        int len = sc.read(buffer);
        System.out.println(new String(buffer.array(),0,len));
        ByteBuffer buff = ByteBuffer.allocate(1024);
        buff.put("滚".getBytes());
        buff.flip();
        sc.write(buff);
        //关流;
        sc.close();
    }
}
